<?php

	class Default_Form_Registeruser extends Zend_Form
	{
		private $_action;
		
		public function __construct($action)
		{
			$this->_action = $action;
			
			parent::__construct();
		}
		
		public function init()
		{
			$this->addElementPrefixPath('App_Validate','App/Validate',Zend_Form_Element::VALIDATE);
			
			Zend_Dojo::enableForm($this);
			foreach ($this->getSubForms() as $subForm)
			{
            	Zend_Dojo::enableForm($subForm);
       		}
			
			$this->setAction($this->_action);
			$this->setMethod('post');
			$this->setAttrib('class','form');
			
			$firstName = new Zend_Form_Element_Text('firstName');
			$firstName->setLabel(Zend_Registry::get('translate')->_('FIRST_NAME').':')
				 ->setRequired(true)
				 ->addValidator('NotEmpty', true)
				 ->addValidator('regex', true, array(Default_Model_Validator::getFirstNameExp()))
				 ->addErrorMessage('*');
			
			$lastName = new Zend_Form_Element_Text('lastName');
			$lastName->setLabel(Zend_Registry::get('translate')->_('LAST_NAME').':')
				 ->setRequired(true)
				 ->addValidator('NotEmpty', true)
				 ->addValidator('regex', true, array(Default_Model_Validator::getLastNameExp()))
				 ->addErrorMessage('*');
				 
			$username = new Zend_Form_Element_Text('username');
			$username->setLabel(Zend_Registry::get('translate')->_('USERNAME').':')
				 ->setRequired(true)
				 ->addValidator('NotEmpty', true)
				 ->addValidator('regex', true, array(Default_Model_Validator::getUsernameExp()))
				 ->addErrorMessage('*');
			
			$pw1 = new Zend_Form_Element_Password('password1');
			$pw1->setLabel(Zend_Registry::get('translate')->_('PASSWORD').':')
				 ->setRequired(true)
				 ->addValidator('NotEmpty', true)
				 ->addValidator('regex', true, array(Default_Model_Validator::getPasswordExp()))
				 ->addValidator('fieldCompare', false, array('password'))
				 ->addErrorMessage('*');
			
			$pw2 = new Zend_Form_Element_Password('password2');
			$pw2->setLabel(Zend_Registry::get('translate')->_('PASSWORD_AGAIN').':')
				 ->setRequired(true)
				 ->addValidator('NotEmpty', true)
				 ->addValidator('fieldCompare', false, array('password', 'eq'))
				 ->addErrorMessage('*');
			
			$email1 = new Zend_Form_Element_Text('email1');
			$email1->setLabel(Zend_Registry::get('translate')->_('EMAIL').':')
				 	->setRequired(true)
				 	->addValidator('NotEmpty', true)
					->addValidator('regex', false, array(Default_Model_Validator::getEmailExp()))
					->addValidator('fieldCompare', false, array('email'))
					->addErrorMessage('*');
			
			$email2 = new Zend_Form_Element_Text('email2');
			$email2->setLabel(Zend_Registry::get('translate')->_('EMAIL_AGAIN').':')
				 	->setRequired(true)
				 	->addValidator('NotEmpty', true)
					->addValidator('fieldCompare', false, array('email', 'eq'))
					->addErrorMessage('*');
					
			$sex = new Zend_Form_Element_Select('sex');
			$sex->setLabel(Zend_Registry::get('translate')->_('SEX').':')
				->addMultiOption(NULL, Zend_Registry::get('translate')->_('CHOOSE_GENDER'))
				->addMultiOption('male', Zend_Registry::get('translate')->_('MALE'))
				->addMultiOption('female', Zend_Registry::get('translate')->_('FEMALE'))
			 	->setRequired(true)
			 	->addValidator('NotEmpty', true)
				->addErrorMessage('*');
			
			$language = new Zend_Form_Element_Select('language');
			$language 	->setLabel(Zend_Registry::get('translate')->_('LANGUAGE').':')
						->setRequired(true)
					 	->addValidator('NotEmpty', true)
					 	->addErrorMessage('*')
						->addMultiOption('0', Zend_Registry::get('translate')->_('CHOOSE_LANGUAGE'));
			$langs = Zend_Registry::get('config')->lang->toArray();
			while($langCode = current($langs))
			{
				$language->addMultiOption(key($langs), $langCode);
				next($langs);
			}			
			
			$captcha = new Zend_Form_Element_Captcha('captcha', array(
			    'label' => Zend_Registry::get('translate')->_('CAPTCHA'),
			    'captcha' => 'Image',
			    'captchaOptions' => array(
			        'wordLen' => 6,
			        'timeout' => 300,
					'font'		=> 'fonts/arial.ttf',
					'imgDir'	=> 'pics/captcha',
					'imgUrl'	=> 'http://spagooy.com/pics/captcha',
					'height'	=> '60px',
					'width'		=> '140px'
			    )
			));
			$captcha->addErrorMessage('*');
			
			$submit = new Zend_Form_Element_Submit('submit');
			$submit->setLabel(Zend_Registry::get('translate')->_('SEND'));
			
			$elements = array($firstName,$lastName,$sex,$language,$username,$pw1,$pw2,$email1,$email2,$captcha,$submit);
				
			$this->addElements($elements);
			  
			$this->setDisableLoadDefaultDecorators(true);
			
			$this->addDecorator('FormElements')
				 ->addDecorator('HtmlTag',array('tag' => 'ul'))
				 ->addDecorator('Form');
 
			$this->setElementDecorators(array(
				'ViewHelper',
				'Errors',
				'Label',
				new Zend_Form_Decorator_HtmlTag(array('tag' => 'li'))				
			));
		
			$submit->removeDecorator('Label');
			$captcha->removeDecorator('ViewHelper');
			$captcha->setDecorators(array(
				'Errors',
				'Label',
				new Zend_Form_Decorator_HtmlTag(array('tag' => 'li', 'class' => 'captcha'))				
			));	
		}
	}